<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        /* ES6的类语法就是ES5的构造函数的语法糖,让他看起来更像类语法 */
        function Person(name,age){
            /* 属性 */
            this.name = name;
            this.age = age;

            this.speak = function(){
                console.log("说");
            }
        }
        Person.prototype.eat = function(){
            console.log(this.name + "吃!");
        }
        /* 创建两个对象 */
        let  p1 = new Person("郑香",18)
        let  p2 = new Person("文渊",18)
        p1.eat();
        p2.eat();
        console.log(p1,p2);

        console.log("---------------------");

        class Student{
            /* 属性 */
            constructor(name,age){
                this.name = name;
                this.age = age;
            }
            /* 原型身上得到方法 */
            eat(){
                console.log(this.name+"吃!");
            }
            /* 自身身上的方法typescript*/
            static speak(){
                console.log("自身身上的方法");
            }
        }
        let s1 = new Student("文渊",18)
        let s2 = new Student("郑香",19)
        s1.eat()
        s2.eat();
        console.log(s1,s2);
    </script>
</body>
</html>